package com.study.shop.entity.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 返回数据的通用类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class R<T> {
    private int code;
    private String message;
    private T data;
    private boolean ok;

    public static R<Object> success() {
        return new R<>(200, "success", null, true);
    }

    public static <T> R<T> success(T data) {
        return new R<>(200, "success", data, true);
    }


    public static <T> R<T> success(int code, T data) {
        return new R<>(code, "success", data, true);
    }

    public static <T> R<T> success(int code, String message, T data) {
        return new R<>(code, message, data, true);
    }

    public static R<Object> error(String message) {
        return new R<>(400, message, null, false);
    }

    public static  R<Object> error() {
        return new R<>(400, "error", null, false);
    }

    public static <T> R<T> error(T data) {
        return new R<>(400, "error", data, false);
    }


}
